/**
	@file Logger.h
*/

#ifndef _LOGGER_H_
#define _LOGGER_H_

#include<Windows.h>
#include<iostream>

#include"Head.h"
class zLogger
{
public:
	zLogger()
	{
		AllocConsole();
	}

	~zLogger()
	{
		FreeConsole();
	}

	void Log(const char* str)
	{
		SYSTEMTIME time;
		GetSystemTime(&time);

		int length = strlen(str);
		char* buffer = new char[length + 50];

		// set the color of console
		static HANDLE hWnd = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(hWnd, FOREGROUND_RED | FOREGROUND_GREEN);

		sprintf(buffer,"[%d/%d %d:%d] %s \r", time.wMonth, time.wDay, (time.wHour + 8) % 24, time.wMinute, str );
		
		std::cout << buffer <<std::endl;

		delete[] buffer;
	}
	
	void Log(const char* format,va_list args)
	{
		char buffer[512];
		vsprintf(buffer,format,args);

		Log(buffer);
	}
};

inline void LogInof(const char*format,...)
{
	va_list args;
	
	va_start(args,format);
	gEnv->logger->Log(format,args);
	
	va_end(args);
}

#endif